package Model;

import Entity.Admin;
import Entity.Role;
import Manager.AdminManager;
import Manager.Manager;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author CONG
 */
public class AdminTableModel extends AbstractTableModel {

    private AdminManager am;
    private Manager manager;
    private Admin ad;
    public AdminTableModel(Manager manager) {
        this.manager = manager;
    }

    public void setAD(Admin ad) {
        this.ad = ad;
        this.fireTableDataChanged();
    }
    
    @Override
    public int getRowCount() {
        return manager.getAdminManager().getSize();
    }

    @Override
    public int getColumnCount() {
        return 5;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Admin ad = manager.getAdminManager().getAdmin(rowIndex);
        int roleCode = ad.getRoleCode();
        Role r = null;
        for (int i = 0; i < manager.getRoleManager().getSize(); i++) {
            if (manager.getRoleManager().getRole(i).getRoleCode() == roleCode) {
                r = manager.getRoleManager().getRole(i);
            }
        }

        switch (columnIndex) {
            case 0:
                return ad.getAdminID();
            case 1:
                return ad.getAdminAccount();
            case 2:
                return ad.getFullName();
            case 3:
                return ad.getAddress();
            case 4:
                return r.getName();
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID";
            case 1:
                return "Name";
            case 2:
                return "Full Name";
            case 3:
                return "Address";
            case 4:
                return "Permission";
            default:
                return null;
        }
    }

    public int getSize() {
        return manager.getAdminManager().getSize();
    }

    public Admin getAdmin(int index) {
        return manager.getAdminManager().getAdmin(index);
    }

    public void getAdminList(ArrayList<Admin> ad) {
        manager.getAdminManager().getAdminList(ad);
    }

    public boolean addAdmin(Admin ad) {
        return manager.getAdminManager().addAdmin(ad);
    }
    public boolean removeAdmin(Admin ad){
        return manager.getAdminManager().deleteAdmin(ad);
    }
    public boolean editProfile(Admin ad){
        return manager.getAdminManager().editProfile(ad);
    }
}
